﻿using Breeze.WebApi;
using LunchLearn.WebApi.Domain;
using LunchLearn.WebApi.Repository;
using System;
using System.Collections.Generic;

namespace LunchLearn.WebApi.Infrastructure.TrackingServices
{
    public class ChangeTrackingService : IChangeTrackingService
    {
        private readonly Dictionary<Type,Func<IChangeTrackingService>> _trackingServices;

        public ChangeTrackingService(Func<OrderTrackingService> orderTrackingService, Func<OrderLineTrackingService> orderLineTrackingService)
        {
            _trackingServices = new Dictionary<Type,Func<IChangeTrackingService>>();
            _trackingServices[typeof(Order)] = orderTrackingService;
            _trackingServices[typeof(OrderLine)] = orderLineTrackingService;
        }

        public void Track(EntityInfo entityInfo, LunchLearnContext context)
        {
            if (_trackingServices.ContainsKey(entityInfo.Entity.GetType()))
            {
                _trackingServices[entityInfo.Entity.GetType()]().Track(entityInfo, context);
            }
        }
    }
}